package com.acwing.partition38;

import java.io.*;

/**
 * @author rkc
 * @date 2022/7/20 9:08
 */
public class AC3715最少交换次数_暴力 {

    private static final int N = 1010;
    private static int[] w = new int[N], temp = new int[N];
    private static int n;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = nextInt();
        for (int i = 0; i < n; i++) w[i] = nextInt();
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < i; j++) {
                if (w[j] > w[i]) {
                    temp[w[i]]++;
                }
            }
        }
        for (int i = 1; i <= n; i++) {
            writer.print(temp[i] + " ");
            ans += temp[i];
        }
        writer.format("\n%d", ans);
        writer.flush();
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}
